package com.jt.provider.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

public class TimeInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        System.out.println("===preHandle===");
        LocalTime now = LocalTime.now();
        int hour = now.getHour();
        if (hour<8 || hour>=21) {
            throw new RuntimeException("请在规定时间访问（8:00--21:00）");
        }
        return true;
    }
}
